package work;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Random;
import java.util.stream.Collectors;

public class zy4 {
	public static void main(String[] args) throws NumberFormatException, IOException {
		ArrayList<Student> list = new ArrayList<>();
		BufferedReader br=new BufferedReader(new FileReader("name4.txt"));
		String line;
		while((line=br.readLine())!=null){
			String[] split = line.split("-");
			Student s = new Student(split[0], split[1], Integer.parseInt(split[2]),Double.parseDouble(split[3]));
			list.add(s);
		}
		br.close();
		double weights=0;
		Student student = new Student();
		for(Student s:list){
			weights+=s.getWeight();
		}
		if(weights==10){
			for(Student s:list){
				s.setWeight(0);
			}
		}
		ArrayList<Student> rest=(ArrayList<Student>) list.stream().filter(s->s.getWeight()==0.0).collect(Collectors.toList());
		Random rd = new Random();
		int index = rd.nextInt(rest.size());
		student = rest.get(index);
		System.out.println(student.getName());
		student.setWeight(student.getWeight()+1);
		BufferedWriter bw=new BufferedWriter(new FileWriter("name4.txt"));
		for(Student s:list){
			bw.write(s.toString());
			bw.newLine();
		}
		bw.close();
	}
}
